﻿//  --------------------------------
//  Copyright (c) 2010 Michael Schuler, Sascha Burger. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://p2pmessaging.codeplex.com/license
//  ---------------------------------
using System;
using NUnit.Framework;
using p2pMessaging.BL;
using p2pMessaging.BL.Model;
using p2pMessaging.Contracts;
using p2pMessaging.Interfaces;
using p2pMessaging.Interfaces.Contact;
using Rhino.Mocks;

namespace p2pMessaging.Tests
{
	[TestFixture]
	public class ContactServiceTest
	{
		private IContactService myContactService;

		[SetUp]
		public void setUp()
		{
			myContactService = ServiceLocator.Get<IContactService>();
		}
		
		[Test]
		public void createContact()
		{
			IContact contact = new Contact();
			
			Assert.IsNotNull(contact.Id);

			myContactService.Store(contact);

			IContact fromDb = myContactService.Get(contact.Id);
			Assert.IsNotNull(fromDb);
			
			myContactService.Delete(fromDb);
			
			Assert.IsNull(myContactService.Get(contact.Id));
		}

		[Test]
		public void mock()
		{
			IContactService contactService;
			string id = Guid.NewGuid().ToString();
				
			MockRepository mocks = new MockRepository();
			
			using (mocks.Record())
			{
				IPersistenceService persistenceService = mocks.StrictMock<IPersistenceService>();
				contactService = new ContactService(persistenceService);

				IContact returnValue = mocks.StrictMock<IContact>();

				Expect.Call(persistenceService.Get<IContact>(id)).IgnoreArguments().Return(returnValue);
			}
			
			using (mocks.Playback())
			{
				IContact result = contactService.Get(id);
			}
			
			mocks.Playback();
			mocks.VerifyAll();
		}
	}
}
